package com.ruoyi.taskSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.taskSys.domain.MHouseholdTask;
import com.ruoyi.taskSys.service.IMHouseholdTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住户核酸任务Controller
 * 
 * @author ruoyi
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/taskSys/hstask")
public class MHouseholdTaskController extends BaseController
{
    @Autowired
    private IMHouseholdTaskService mHouseholdTaskService;

    /**
     * 查询住户核酸任务列表
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:list')")
    @GetMapping("/list")
    public TableDataInfo list(MHouseholdTask mHouseholdTask)
    {
        startPage();
        List<MHouseholdTask> list = mHouseholdTaskService.selectMHouseholdTaskList(mHouseholdTask);
        return getDataTable(list);
    }

    /**
     * 导出住户核酸任务列表
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:export')")
    @Log(title = "住户核酸任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MHouseholdTask mHouseholdTask)
    {
        List<MHouseholdTask> list = mHouseholdTaskService.selectMHouseholdTaskList(mHouseholdTask);
        ExcelUtil<MHouseholdTask> util = new ExcelUtil<MHouseholdTask>(MHouseholdTask.class);
        util.exportExcel(response, list, "住户核酸任务数据");
    }

    /**
     * 获取住户核酸任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mHouseholdTaskService.selectMHouseholdTaskById(id));
    }

    @GetMapping(value = "/send/{id}")
    public AjaxResult sendMessage(@PathVariable("id") Long id)
    {
        return success(mHouseholdTaskService.sendMessage(id));
    }

    /**
     * 新增住户核酸任务
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:add')")
    @Log(title = "住户核酸任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MHouseholdTask mHouseholdTask)
    {
        return toAjax(mHouseholdTaskService.insertMHouseholdTask(mHouseholdTask));
    }

    /**
     * 修改住户核酸任务
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:edit')")
    @Log(title = "住户核酸任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MHouseholdTask mHouseholdTask)
    {
        return toAjax(mHouseholdTaskService.updateMHouseholdTask(mHouseholdTask));
    }

    /**
     * 删除住户核酸任务
     */
    @PreAuthorize("@ss.hasPermi('taskSys:hstask:remove')")
    @Log(title = "住户核酸任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mHouseholdTaskService.deleteMHouseholdTaskByIds(ids));
    }
}
